import 'package:flutter/material.dart';
// 标签组件
class CommonTag extends StatelessWidget {
  final String title;// 标题
  final Color color;// 文字颜色
  final Color backgroundColor;// 背景颜色

  const CommonTag({super.key, this.title = '--', this.color = Colors.black,this.backgroundColor = Colors.grey});

  // 根据标题封装工厂构造函数
  factory CommonTag.fromTitle(String title){
    switch (title){
      case '近地铁':
        return CommonTag(
          title: title,
          color: Colors.red,
          backgroundColor: Colors.red[50]?? Colors.grey,
        );
      case '公寓':
        return CommonTag(
          title: title,
          color: Colors.orange,
          backgroundColor: Colors.orange[50]?? Colors.grey,
        );
      case '精装':
        return CommonTag(
          title: title,
          color: const Color.fromARGB(255, 10, 141, 119),
          backgroundColor: const Color.fromARGB(255, 224, 251, 255)?? Colors.grey,
        );
      case '月租':
        return CommonTag(
          title: title,
          color: const Color.fromARGB(255, 23, 56, 204),
          backgroundColor: const Color.fromARGB(255, 224, 224, 255)?? Colors.grey,
        );
      case '独立卫生间':
        return CommonTag(
          title: title,
          color: const Color.fromARGB(255, 204, 177, 23),
          backgroundColor: const Color.fromARGB(255, 255, 253, 224)?? Colors.grey,
        );
      case '押一付一':
        return CommonTag(
          title: title,
          color: const Color.fromARGB(255, 252, 37, 22),
          backgroundColor: const Color.fromARGB(255, 255, 230, 224)?? Colors.grey,
        );
      case '集中供暖':
        return CommonTag(
          title: title,
          color: Colors.blue,
          backgroundColor: Colors.blue[50]?? Colors.grey,
        );
      case '随时看房':
        return CommonTag(
          title: title,
          color: Colors.green,
          backgroundColor: Colors.green[50]?? Colors.grey,
        );
       case '新上':
        return CommonTag(
          title: title,
          color: Colors.pink,
          backgroundColor: Colors.pink[50]?? Colors.grey,
        );
      default:
        return CommonTag(title: title, color: Colors.black, backgroundColor: const Color.fromARGB(255, 223, 220, 220)); // 使用默认样式
    }
  }
  @override
  Widget build(BuildContext context) {
    return Container(
      margin: const EdgeInsets.only(right: 5.0),
      padding: const EdgeInsets.only(left: 4.0,right: 4.0,top: 2.0,bottom: 2.0),
      decoration: BoxDecoration(
        color: backgroundColor,
        borderRadius: BorderRadius.circular(8.0),
      ),
      child: Text(
        title,
        style: TextStyle(fontSize: 12.0,color: color),
      )
    );
  }
}